﻿Imports iConverter.Contracts
Imports System.Drawing
Imports System.Configuration
Imports iConverter.Extensions
Imports iConverter.Models
Imports iConverter.Core




Namespace Extensions
    ''' <summary>
    ''' 用于后期处理插件的处理器
    ''' </summary>
    ''' <remarks></remarks>
    Public Class Processer
        Implements IDisposable


        ''' <summary>
        ''' 包含自己的插件
        ''' </summary>
        ''' <remarks></remarks>
        Dim _plugin As PostProcessing

        ''' <summary>
        ''' 处理器对象
        ''' </summary>
        ''' <remarks></remarks>
        Dim _processer As IProcessing

        ''' <summary>
        ''' 处理器元数据
        ''' </summary>
        ''' <remarks></remarks>
        Dim _metadata As IProcessingMetadata


        ''' <summary>
        ''' 分组信息
        ''' </summary>
        ''' <remarks>
        ''' 用于命令显示的分组
        ''' </remarks>
        Dim _groupName As String


        ''' <summary>
        ''' 创建新的处理器实例
        ''' </summary>
        ''' <param name="groupName">处理器分组名</param>
        ''' <param name="plugin">提供处理器的插件</param>
        ''' <param name="processer">处理器</param>
        ''' <remarks></remarks>
        Friend Sub New(ByVal groupName As String, plugin As PostProcessing , processer As Object)
            Me._plugin = plugin
            Me._groupName = groupName

            Me._processer = DirectCast(processer, IProcessing)
            Me._metadata = DirectCast(processer, IProcessingMetadata)


            Me._sIcon = ExtensionsFactory.TryGetImageSource(Me.Metadata.SmallIcon)

            Me._icon = ExtensionsFactory.TryGetImageSource(Me.Metadata.Icon)


        End Sub



        ''' <summary>
        ''' 获取或设置一个值， 指示 此处理器是否被默认选择
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property isSelected As Boolean 



        ''' <summary>
        ''' 分组信息
        ''' </summary>
        ''' <remarks>
        ''' 用于命令显示的分组
        ''' </remarks>
        Public ReadOnly Property GroupName() As String
            Get
                Return _groupName
            End Get
        End Property

        ''' <summary>
        ''' 元数据
        ''' </summary>
        ''' <remarks></remarks>
        Private ReadOnly Property Metadata() As IProcessingMetadata
            Get
                Return _metadata
            End Get
        End Property
        ''' <summary>
        ''' 处理器对象
        ''' </summary>
        ''' <remarks></remarks>
        Private ReadOnly Property Processer() As IProcessing
            Get
                Return _processer
            End Get
        End Property
        ''' <summary>
        ''' 提供处理器的插件
        ''' </summary>
        ''' <remarks></remarks>
        Friend ReadOnly Property Plugin() As Plugin
            Get
                Return Me._plugin
            End Get
        End Property


#Region "元数据"

        ''' <summary>
        ''' 获取插件描述
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property Description As String
            Get
                Return Me.Metadata.Description
            End Get
        End Property

        ''' <summary>
        ''' 获取插件名称
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property Name As String
            Get
                Return Me.Metadata.Name
            End Get
        End Property




        ''' <summary>
        ''' 获取插件的GUID
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property ID As System.Guid
            Get
                Return Me.Metadata.ID
            End Get
        End Property

        Dim _icon As ImageSource

        ''' <summary>
        ''' 获取用于显示的图标
        ''' </summary>
        ''' <value></value>
        ''' <returns>如果没有可用图标则返回Nothing，否则返回图标的Bitmap对象</returns>
        ''' <remarks>大小在32*32内为最佳</remarks>
        Public ReadOnly Property Icon As ImageSource
            Get
                Return Me._icon
            End Get
        End Property


        Dim _sIcon As ImageSource

        ''' <summary>
        ''' 获取小图标
        ''' </summary>
        ''' <value></value>
        ''' <returns>如果没有可用图标则返回Nothing，否则返回图标的Bitmap对象</returns>
        ''' <remarks>用于显示在菜单中（16 x 16 )小图标</remarks>
        Public ReadOnly Property SmallIcon As ImageSource
            Get
                Return Me._sIcon
            End Get
        End Property
#End Region



#Region "处理器实现"

        Public Sub Processing(doc As ConvertDocument)

            'TODO: 添加代码

            Me.Processer.Processing(doc)

        End Sub
#End Region



#Region "IDisposable Support"
        Private disposedValue As Boolean ' 检测冗余的调用

        ' IDisposable
        Protected Overridable Sub Dispose(disposing As Boolean)
            If Not Me.disposedValue Then
                If disposing Then

                End If

                Me._groupName = Nothing
                Me._metadata = Nothing
                Me._processer = Nothing
                Me._plugin = Nothing
            End If
            Me.disposedValue = True
        End Sub


        'Protected Overrides Sub Finalize()
        '    ' 不要更改此代码。请将清理代码放入上面的 Dispose(ByVal disposing As Boolean)中。
        '    Dispose(False)
        '    MyBase.Finalize()
        'End Sub

        ' Visual Basic 添加此代码是为了正确实现可处置模式。
        Public Sub Dispose() Implements IDisposable.Dispose
            ' 不要更改此代码。请将清理代码放入上面的 Dispose(ByVal disposing As Boolean)中。
            Dispose(True)
            GC.SuppressFinalize(Me)
        End Sub
#End Region

    End Class

End Namespace
